package com.net.xpay.common.manager.impl.invoice;

import com.google.common.base.Preconditions;
import com.net.common.dao.BasicMapper;
import com.net.common.manager.AbstractManager;
import com.net.xpay.common.dao.invoice.InvoiceTitleMapper;
import com.net.xpay.common.domain.invoice.InvoiceTitle;
import com.net.xpay.common.manager.invoice.InvoiceTitleManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;


@Component
public class InvoiceTitleManagerImpl extends AbstractManager<InvoiceTitle> implements InvoiceTitleManager{

    @Autowired
    private InvoiceTitleMapper mapper;


    @Override
    protected BasicMapper<Long, InvoiceTitle> getMapper() {
        return mapper;
    }



    @Override
    public List<InvoiceTitle> listByUserId(Long userId) {
        Preconditions.checkArgument(userId != null);
        return nonEmptyList(mapper.listByUserId(userId));
    }

    @Override
    public InvoiceTitle findById(Long userId, Long id) {
        Preconditions.checkArgument(userId != 0 || id != 0);
        InvoiceTitle condition = new InvoiceTitle();
        condition.setUserId(userId);
        condition.setId(id);
        return getByCondition(condition);
    }
}
